# 文件名: ex3_playwright
# 当前用户: shiping.zheng
# 当前日期: 2025/1/9
# 当前时间: 11:15
# 项目名称: Flag
"""
模块描述:
    playwright异步处理
"""
import asyncio
from playwright.async_api import async_playwright

async def demo(url):
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto(url)
        title = await page.title()
        print(f"Title of {url}: {title}")
        await browser.close()

async def main():
    # 定义要访问的 URL 列表
    urls = [
        'https://xuntian-test2.tclpv.com/getechLogin',
        'https://xuntian-test1.tclpv.com/getechLogin',
    ]

    # 创建任务列表
    tasks = [demo(url) for url in urls]

    # 并行执行所有任务（异步执行）
    await asyncio.gather(*tasks)

# 运行异步主函数
asyncio.run(main())